package com.yehuo.app.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuo.app.dto.FindOrderDTO;
import com.yehuo.app.entity.dto.SelectOrderDto;
import com.yehuo.app.mapper.OrderMapper;
import com.yehuo.app.model.R;
import com.yehuo.app.service.OrderService;
import com.yehuo.app.vo.OrderListVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 订单业务层
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    /**
     * 查询订单列表
     * @param selectOrderDto
     * @return
     */
    @Override
    public R selectOrder(SelectOrderDto selectOrderDto) {
        //获取查询条件
        Map<String, Object> conditions = selectOrderDto.getCondition();
        PageHelper.startPage(selectOrderDto.getPage(),selectOrderDto.getLimit());
        //查询
        List<Map<String, Object>> orderList = orderMapper.selectOrdersByConditions(conditions);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(orderList);
        R<Map<String,Object>> result = new R<>((int) pageInfo.getTotal(), pageInfo.getList());
        return result;
    }
}
